package alo.p6.work;


import org.junit.Test;
import alo.p6.BinaryTreeNode;
//打印所有祖先结点
public class PrintAllAncestors {

    int printAllAncestors(BinaryTreeNode root,BinaryTreeNode node){
        if (root==null) return 0;
        //如果结点有包含node的子结点，为true
        if (root.getLeft()==node||root.getRight()==node||
                printAllAncestors(root.getRight(),node)==1||printAllAncestors(root.getLeft(),node)==1){
            System.out.println(root.getData());
            return 1;
        }
        return 0;
    }
    @Test
    public void test() {
        int[] A = {1, 2, 4, 5, 3, 6, 7};
        int[] B = {4, 2, 5, 1, 6, 3, 7};
        BuildBinaryTree buildBinaryTree = new BuildBinaryTree();
        BinaryTreeNode root = buildBinaryTree.buildBinaryTree(B, A, 0, 6);
        printAllAncestors(root,root.getRight().getRight());
    }
}
